Highlight Controls

Highlight a Record Row Based on a Condition

Description
This customization demonstrates how to highlight a record row based on a condition.
Variables
RecordControl
Select a record control
Conditional Field Control
Select the conditional field control
Applies to
RecordControl class
Code
 
''' 
''' Highlights the record in the PreRender
''' 
Private Sub RecordControl_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender

    ' Compare value to determine if you want to highlight the background of the row.
    ' For example, if ${Conditional Field Control} > 25, then, highlight.
    ' Note: You can also check if the field value equals a certain string,
    ' e.g, ${Conditional Field Control}.Text = "Yes".
    If Double.Parse(Me.${Conditional Field Control}.Text) > 25 Then
    
        ' Find the record row the field value is on.
        Dim recordRow As System.Web.UI.HtmlControls.HtmlTableRow 
        recordRow = CType(Me.FindControl("MyTR"), System.Web.UI.HtmlControls.HtmlTableRow)
        ' This will be used for each cell on the row.
        Dim recordRowCell As System.Web.UI.HtmlControls.HtmlTableCell

        ' Set the background color on the record row in RGB format.
        Dim color As String = "#ffff00"

        ' For each cell, set the background color.
        For Each recordRowCell In recordRow.Cells

            ' Override the record row background color -- since each data cell uses a 
            ' style (by default: table_cell or table_cellr)
            recordRowCell.Style.Add("background-color", color)
        
        Next
        
    End If
    
End Sub
     

Terms of Service Privacy Statement